package com.cskaoyan.controller.wx.user;

import com.cskaoyan.bean.MarketUser;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.vo.wx.user.UserIndexVO;
import com.cskaoyan.service.wx.user.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Mr.Tang
 * @since 2022/09/09 15:49
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {

    private static final int USER_ID = 1;
    @Autowired
    UserService userService;


    @RequestMapping("index")
    public BaseRespVo IndexForUser() {

        // 使用SecurityUtils.getSubject()拿到当前登录用户的信息
        Subject subject = SecurityUtils.getSubject();
        MarketUser primaryPrincipal = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer id = primaryPrincipal.getId();

        UserIndexVO userIndexVO = userService.index(id);

         return BaseRespVo.ok(userIndexVO);
    }

}
